﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication1
{
    class Client
    {
        protected string nume;
        protected string prenume;
        protected int varsta;
        protected List<Masina> masini;

        public Client(string n, string p, int v)
        {
            this.nume = n;
            this.prenume = p;
            this.varsta = v;
            this.masini = null;
        }

        public string getNume()
        {
            return nume;
        }
        public string getPrenume()
        {
            return prenume;
        }
        public int getVarsta()
        {
            return varsta;
        }
        public bool exista(string n, string p, int v)
        {
            if (this.nume == n && this.prenume == p && this.varsta == v)
                return true;
            else
                return false;
        }

        public string print()
        {
            string s = nume + "\t" + prenume + "\t" + varsta;

            return s;
        }
    
        public string printCars()
        {
            string s = "NrCrt\tNume\tTip\tDotari\tDimensiuni\tMotorizare\tCuloare\tTransmisie\n";
            int i = 1;

            if (masini != null)
                foreach (Masina m in masini)
                {
                    s += i + m.print() + "\n";
                    i++;
                }
            return s;
        }

        public int addMasina(string culoare, string trans, string dim, string mot, string dotari, string nume, string tip)
        {
            if (masini == null)
            {
                masini = new List<Masina>();
            }

            Masina m;

            if (existaMasina(culoare, trans, dim, mot, dotari, nume) != null)
                return 1;

            if (tip == "sedan")
                m = new Sedan(culoare, trans, dim, mot, dotari, nume);
            else
                if (tip == "coupe")
                    m = new Coupe(culoare, trans, dim, mot, dotari, nume);
                else
                    if (tip == "mini")
                        m = new Mini(culoare, trans, dim, mot, dotari, nume);
                    else
                        return -1;

            masini.Add(m);

            return 0;
        }

        public Masina existaMasina(string culoare, string trans, string dim, string mot, string dotari, string nume)
        {
            foreach (Masina aux in masini)
                if ( aux.exista(culoare, trans, dim, mot, dotari, nume) )
                    return aux;
                
            return null;
        }

        public void rmMasina(string culoare, string trans, string dim, string mot, string dotari, string nume)
        {
            Masina m = existaMasina(culoare, trans, dim, mot, dotari, nume);

            if ( m != null)
                masini.Remove(m);
        }

    }
}
